using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using netDefect.utils;

namespace netDefect
{
    public partial class netDefect : System.Web.UI.MasterPage
    {
        private int menuIndex = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.User.Identity.IsAuthenticated)
            {
                loggedInText.Text = Constants.welcomeMessageLoggedIn + Page.User.Identity.Name;
            }
            else
            {
                loggedInText.Text = Constants.welcomeMessageNotLoggedIn;
            }
            if (!Page.IsPostBack)
            {
                if (Page.User.IsInRole("Administrators"))
                {
                    menuListing.Items.Add(new ListItem("Administer netDefect", "~/admin/Entities.aspx"));
                }
                if (menuListing.Items[0].Text == "myWorkSpace")
                {
                    subMenuListing.Items.Clear();

                    menuListing.Items[0].Attributes.Add("Class", "current");
                    subMenuListing.Items.Add(new ListItem("myWorkSpace Home", Constants.myWorkspaceLoc + "myWorkspace.aspx"));
                    subMenuListing.Items.Add(new ListItem("myProjects", Constants.myWorkspaceLoc + "myProjects.aspx"));
                    subMenuListing.Items.Add(new ListItem("myTasks", Constants.myWorkspaceLoc + "myTasks.aspx"));
                    subMenuListing.Items.Add(new ListItem("myWorkLogs", Constants.myWorkspaceLoc + "myWorkLog.aspx"));
                    subMenuListing.Items.Add(new ListItem("myProfile", Constants.myWorkspaceLoc + "myProfile.aspx"));

                    subMenuListingBottom.Items.Clear();
                    subMenuListingBottom.Items.Add(new ListItem("myWorkSpace Home", Constants.myWorkspaceLoc + "myWorkspace.aspx"));
                    subMenuListingBottom.Items.Add(new ListItem("myProjects", Constants.myWorkspaceLoc + "myProjects.aspx"));
                    subMenuListingBottom.Items.Add(new ListItem("myTasks", Constants.myWorkspaceLoc + "myTasks.aspx"));
                    subMenuListingBottom.Items.Add(new ListItem("myWorkLogs", Constants.myWorkspaceLoc + "myWorkLog.aspx"));
                    subMenuListingBottom.Items.Add(new ListItem("myProfile", Constants.myWorkspaceLoc + "myProfile.aspx"));

                }
            }
            else
            {
                for (int i = 0; i < menuListing.Items.Count; i++)
                {
                    if (i != menuIndex)
                    {
                        menuListing.Items[i].Attributes.Clear();
                    }
                    else
                    {
                        menuListing.Items[i].Attributes.Add("Class", "current");
                    }
                }
            }

        }

        protected void menuListing_Click(object sender, BulletedListEventArgs e)
        {
            //for (int i = 0; i < menuListing.Items.Count; i++)
            menuIndex = e.Index;
            for (int i = 0; i < menuListing.Items.Count; i++)
            {
                if (i != e.Index)
                {
                    menuListing.Items[i].Attributes.Clear();
                }
                else
                {
                    menuListing.Items[i].Attributes.Add("Class", "current");
                }
            }
            switch (e.Index)
            {
                case 0:
                    subMenuListing.Items.Clear();
                    subMenuListing.Items.Add(new ListItem("myWorkSpace Home", Constants.myWorkspaceLoc + "myWorkspace.aspx"));
                    subMenuListing.Items.Add(new ListItem("myProjects", Constants.myWorkspaceLoc + "myProjects.aspx"));
                    subMenuListing.Items.Add(new ListItem("myTasks", Constants.myWorkspaceLoc + "myTasks.aspx"));
                    subMenuListing.Items.Add(new ListItem("myWorkLogs", Constants.myWorkspaceLoc + "myWorkLog.aspx"));
                    subMenuListing.Items.Add(new ListItem("myProfile", Constants.myWorkspaceLoc + "myProfile.aspx"));
                    break;
                case 1:
                    subMenuListing.Items.Clear();
                    if (Page.User.IsInRole("LPM")) subMenuListing.Items.Add(new ListItem("New Project", Constants.projectLoc + "newProject.aspx"));
                    subMenuListing.Items.Add(new ListItem("All Active Projects", Constants.projectLoc + "Projects.aspx?app=All"));
                    subMenuListing.Items.Add(new ListItem("All Inactive Projects", Constants.projectLoc + "Projects.aspx?app=Inact"));
                    break;
                case 2:
                    subMenuListing.Items.Clear();
                    subMenuListing.Items.Add(new ListItem("Create New Defect", Constants.defectsLoc + "tada.aspx"));
                    subMenuListing.Items.Add(new ListItem("Search Defects", Constants.defectsLoc + "tada.aspx"));
                    break;
                case 3:
                    subMenuListing.Items.Clear();
                    subMenuListing.Items.Add(new ListItem("myCustomers", Constants.customerLoc + "tada.aspx"));
                    subMenuListing.Items.Add(new ListItem("All Active Customers", Constants.customerLoc + "tada.aspx"));
                    subMenuListing.Items.Add(new ListItem("All Inactive Customers", Constants.customerLoc + "tada.aspx"));
                    break;
                case 4:
                    subMenuListing.Items.Clear();
                    subMenuListing.Items.Add(new ListItem("Users", Constants.adminLoc + "Users.aspx"));
                    subMenuListing.Items.Add(new ListItem("Companies", Constants.adminLoc + "Companies.aspx"));
                    subMenuListing.Items.Add(new ListItem("Projects", Constants.adminLoc + "Projects.aspx"));
                    subMenuListing.Items.Add(new ListItem("Entities", Constants.adminLoc + "entities.aspx"));
                    break;
                default:
                    subMenuListing.Items.Clear();
                    break;
            }
        }
    }
}
